package com.qf.service.impl;

import com.qf.dao.UserMapper;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Criteria;
import org.springframework.data.relational.core.query.Query;
import org.springframework.data.relational.core.query.Update;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/22 19:56
 */
@Service
public class UserServiceImpl implements UserService {
    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

//    private R2dbcEntityTemplate r2dbcEntityTemplate;
//    @Autowired
//    public void setR2dbcEntityTemplate(R2dbcEntityTemplate r2dbcEntityTemplate) {
//        this.r2dbcEntityTemplate = r2dbcEntityTemplate;
//    }

    @Override
    public Mono<User> findById(Integer id) {
        //默认情况下类名首字母小写就是表名
//        return r2dbcEntityTemplate.selectOne(Query.query(Criteria.where("userId").is(id)),User.class);

       return userMapper.findById(id);
    }
    @Override
    public void addUser(User user) {
        userMapper.save(user).subscribe();
    }

    @Override
    public Flux<User> findAllUser() {
       return userMapper.findAll();
    }

    @Override
    public Flux<User> findByNameLike(String name) {
        return userMapper.findByNameLike(name);
    }

    @Override
    public Mono<User> findByNameEquals(String name) {
       return userMapper.findByNameEquals(name);
    }

    @Override
    public Mono<Integer> deleteByNameEquals(String name) {
      return userMapper.deleteByNameEquals(name);
    }

    @Override
    public void updateUser(User user) {
      userMapper.updateUserById(user);

    }

    @Override
    public Mono<User> findFirstByNameLike(String name) {
     return    userMapper.findFirstByNameLike(name);

    }
}
